home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / src / md.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-02  |  3.0 KB  |  87 lines

  1. /*
  2.  
  3.     File: md.c
  4.  
  5.     Copyright (C) 1998-2004 Christophe GRENIER <grenier@cgsecurity.org>
  6.   
  7.     This software is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.   
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.   
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  */
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "types.h"
  25. #include "common.h"
  26. #include "md.h"
  27. #include "intrface.h"
  28. #include "fnctdsk.h"
  29. int check_MD(t_param_disk *disk_car,t_diskext *partition,const int debug)
  30. {
  31.   unsigned char buffer[8*SECTOR_SIZE];
  32.   dword offset=MD_NEW_SIZE_SECTORS(partition->part_size);
  33.   if(disk_car->read(disk_car,8, &buffer, partition->lba+offset)!=0)
  34.   { return 1; }
  35.   if(test_MD(disk_car,(struct mdp_superblock_s*)&buffer,partition,debug,0)!=0)
  36.     return 1;
  37.   set_MD_info(disk_car,(struct mdp_superblock_s*)&buffer,partition,debug,0);
  38.   return 0;
  39. }
  40.  
  41. int set_MD_info(t_param_disk *disk_car, const struct mdp_superblock_s *sb,t_diskext *partition,const int debug, const int dump_ind)
  42. {
  43.   unsigned int i;
  44.   sprintf(partition->name,"md%u",sb->md_minor);
  45.   sprintf(partition->info,"Raid %u: devices",sb->level);
  46.   for(i=0;i<MD_SB_DISKS;i++)
  47.   {
  48.     if(sb->disks[i].major!=0 && sb->disks[i].minor!=0)
  49.     {
  50.       if(strlen(partition->info)<sizeof(partition->info)-26)
  51.       { 
  52.     sprintf(&partition->info[strlen(partition->info)]," (%u,%u)",sb->disks[i].major,sb->disks[i].minor);
  53.     if(sb->disks[i].major==sb->this_disk.major && sb->disks[i].minor==sb->this_disk.minor)
  54.       sprintf(&partition->info[strlen(partition->info)],"*");
  55.       }
  56.     }
  57.   }
  58.   return 0;
  59. }
  60.  
  61. int recover_MD(t_param_disk *disk_car, const struct mdp_superblock_s *sb,t_diskext *partition,const int debug, const int dump_ind)
  62. {
  63.   if(test_MD(disk_car,sb,partition,debug,dump_ind)!=0)
  64.     return 1;
  65.   set_MD_info(disk_car,sb,partition,debug,dump_ind);
  66.   partition->part_type=(unsigned char)P_RAID;
  67.   partition->lba=partition->lba-(sb->size<<1);
  68.   partition->part_size=(sb->size<<1)+MD_RESERVED_SECTORS;
  69.   return 0;
  70. }
  71.  
  72. int test_MD(t_param_disk *disk_car, const struct mdp_superblock_s *sb,t_diskext *partition,const int debug, const int dump_ind)
  73. {
  74.   if(sb->md_magic==(unsigned int)MD_SB_MAGIC)
  75.   {
  76.     if(dump_ind!=0)
  77.     {
  78.       ecrit_rapport("\nRaid magic value at %u/%u/%u\n", LBA2cylinder(disk_car,partition->lba),LBA2head(disk_car,partition->lba),LBA2sector(disk_car,partition->lba));
  79.       /* There is a little offset ... */
  80.       dump(stdscr,sb,SECTOR_SIZE);
  81.     }
  82.     partition->upart_type=UP_RAID;
  83.     return 0;
  84.   }
  85.   return 1;
  86. }
  87.